function loadPopup(src, width, height){
    $.modal('<iframe src="' + src + '" height="'+height+'" width="'+width+'" frameborder="no">', {
            closeHTML:"",
            containerCss:{
                    border: "1px solid",
                    backgroundColor: "#fff",
                    borderColor: "#C3C3C3",
                    height: height,
                    padding: 5,
                    width: width
            },
            overlayClose:false,
            onOpen: function (dialog) {
                dialog.overlay.fadeIn('slow', function () {
                    dialog.data.hide();
                    dialog.container.fadeIn('slow', function () {
                        dialog.data.slideDown('slow');
                    });
                });
            }
    });
}

function addProductItem(){
    table = parent.$('#table_product_popup_grid');
    ids = parent.$('#item_id_list');
    index = 0
    $("INPUT[name='select-row[]']").each(function(i){
        if($('#'+this.id).is(':checked')){
            if(ids.val()!='')
                ids.attr('value',ids.val()+','+$('#'+this.id).val());
            else
                ids.attr('value',$('#'+this.id).val());

            data = $('#tr-product-grid-'+i).html();
            data += '<td><img id="remove-item-'+$('#'+this.id).val()+'" src="'+parent.assetPath+'/gridview/delete.png" onclick="removeOneItem('+$('#'+this.id).val()+')"/></td>';
            table.html(table.html()+'<tr class="'+$('#tr-product-grid-'+i).attr('class')+'">'+data+'</tr>');
            index++;
        }
    });
    if($('#item_id_list').val()!='')
        parent.$('#btn-delete-rows').removeAttr('disabled');

    parent.$.modal.close();
}

function addPopupItems(tblId, tabName){
    table = parent.$('#'+tblId);
    
    if(tabName == 'undefined')
    {
        var tabName = 'item';
    }
        
    
    ids = parent.$('#'+tabName+'_ids');
    
    var index = 0;
    $("INPUT[name='select-row[]']").each(function(i){
        if($('#'+this.id).is(':checked')){
            if(ids.val()!='')
                ids.attr('value',ids.val()+','+$('#'+this.id).val());
            else
                ids.attr('value',$('#'+this.id).val());

            data = $('#tr-'+tabName+'-grid-'+i).html();

            //For category table only
            if(tabName == 'category')
            {
                if(index == 0)
                {
                    data += '<td> <input type="radio" checked="checked" name="Product[primary_category_id]" value="'+$('#'+this.id).val()+'"/> </td>';
                }
                else
                {
                    data += '<td> <input type="radio" name="Product[primary_category_id]" value="'+$('#'+this.id).val()+'"/> </td>';
                }
                
            }
            data += '<td><img id="remove-'+tabName+'-'+$('#'+this.id).val()+'" src="'+parent.assetPath+'/gridview/delete.png" onclick="removeOneItem('+$('#'+this.id).val()+', \''+ tabName +'\')"/></td>';
            table.html(table.html()+'<tr class="'+$('#tr-'+tabName+'-grid-'+i).attr('class')+'">'+data+'</tr>');
            index++;
        }
    });
    if($('#'+tabName+'_ids').val()!='')
        parent.$('#btn-delete-rows').removeAttr('disabled');

    parent.$.modal.close();
}

function addBrand()
{
    if($(".choseModel:checked").length > 0)
    {
        parent.$("#Product_brand_id").val($(".choseModel:checked").val());
        parent.$("#Product_brand_name").val($(".choseModel:checked").attr("rel"));
    }
    parent.$.modal.close();
}

function addStore()
{
    if($(".choseModel:checked").length > 0)
    {
        parent.$("#Product_store_id").val($(".choseModel:checked").val());
        parent.$("#Product_store_name").val($(".choseModel:checked").attr("rel"));
    }
    parent.$.modal.close();
}